package com.repair.miniApp.service.impl;

import com.repair.miniApp.domain.User;
import com.repair.miniApp.mapper.UserMapper;
import com.repair.miniApp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.Date;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String account, String password, int role) {
        // 根据账号和角色查询用户
        User user = userMapper.selectUserByAccountAndPasswordAndRole(account, password,role);

        // 检查用户是否存在且密码是否正确
        if (user != null && user.getPassword().equals(password)) {
            return user;
        }

        // 如果用户不存在或密码错误，返回 null 或抛出异常
        return null;
    }

    @Override
    public boolean register(String name,String account, String password, int role, String phone) {
        User user = new User();
        user.setName(name);
        user.setAccount(account);
        user.setPassword(password);
        user.setRole(role);
        user.setPhone(phone);
        user.setCreateTime(new Date());

        return userMapper.insertUser(user) > 0;
    }



}
